package com.briup.cms.web.controller;

import com.briup.cms.bean.Article;
import com.briup.cms.bean.Config;
import com.briup.cms.service.IArticleService;
import com.briup.cms.service.IConfigService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


    @Api(description = "栏目管理相关接口")
    @RestController
    @RequestMapping("/article")
    public class ArticleController {
        @Autowired
        private IArticleService articleService;

        @ApiOperation("查询所有")
        @GetMapping("findAll")
        public Message findAll(){
            List<Article> list = articleService.findAll();
            return MessageUtil.success(list);
        }

        @ApiOperation("保存或更新")
        @PostMapping("saveOrUpdate")
        public Message saveOrUpdate(Article article){
            articleService.saveOrUpdate(article);
            return MessageUtil.success("操作成功");
        }

        @ApiOperation("根据id删除")
        @GetMapping("deleteById")
        @ApiImplicitParams(
                @ApiImplicitParam(name = "id",value = "主键", required = true,paramType = "query")
        )
        public Message deleteById(long id){
            articleService.deleteById(id);
            return MessageUtil.success("删除成功");
        }

    }


